package cn.starrysky108.simpleerp.finance.controller;


import cn.starrysky108.simpleerp.core.base.BaseController;
import cn.starrysky108.simpleerp.core.base.BaseResponseEntity;
import cn.starrysky108.simpleerp.finance.entity.FinanceCredit;
import cn.starrysky108.simpleerp.finance.service.FinanceCreditService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 赊账订单表 前端控制器
 * </p>
 *
 * @author Carl Lee
 * @since 2021-08-14
 */
@RestController
@Api(tags = "赊账管理")
@RequestMapping("/finance/credits")
public class FinanceCreditController extends BaseController<FinanceCreditService, FinanceCredit> {
    protected FinanceCreditController(HttpServletRequest request, HttpServletResponse response, FinanceCreditService service) {
        super(request, response, service);
    }

    @ApiOperation("赊账单查询")
    @GetMapping("/search")
    public List<FinanceCredit> search() {
        //to do
        return null;
    }

    @ApiOperation("绑定订单")
    @PutMapping("/{id}/sales/{salesId}")
    public BaseResponseEntity<FinanceCredit> bindOrder(@PathVariable Long id, @PathVariable Long salesId) {
        Assert.notNull(id, "赊账单id不能为空");
        Assert.notNull(salesId, "销售订单id不能为空");
        FinanceCredit entity = new FinanceCredit();
        entity.setId(id);
        entity.setSalesId(salesId);
        service.updateById(entity);
        return BaseResponseEntity.success(entity);
    }


}
